const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    alllist: [],
    lastlist: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    if(options.mebid){
      wx.setNavigationBarTitle({
        title: '转账历史',
      });
      that.zhuanzhang(options.mebid, options.fraccid);
    }else{
      if(options.type){

      }else{
        that.tixian();
      }
    }
  },
  tixian:function(){
    var that = this;
    // 获取成员信息
    var datas = {};
    var mebid = (wx.getStorageSync('userinfo')).MebID;
    datas.where = 'MebID =' + mebid + " and AccID =" + wx.getStorageSync('depid');
    console.log(datas.where)
    datas.summary = 1;
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          alllist: res.data.data,
          total: post.toDecimal2(res.data.summary.OutMoney),
          num: res.data.data.length
        });
        // that.getalldata(res.data.data[0].MebID);
      }
    }
    var res2 = post.getdata("/BO/AP_CashPayApply/Query", datas, datacall);
  },
  //转账历史查询
  zhuanzhang:function(mebid,fmebid){
    var that = this;
    var datas = {};
    var url = "/BO/TR_Detail/Query";
    var where = "AccID = '" + mebid + "' and ToAccID ='" + fmebid + "'";
    datas.where = where;
    datas.summary=1;
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        var moneyhistory = [];
        for (var i = 0; i < res.data.data.length; i++) {
          moneyhistory[i] = res.data.data[i];
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.split(' ')[0];
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.replace("-", '.');
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.replace("-", '.');
        }
        that.setData({
          total: res.data.summary.MnyHap?post.toDecimal2(res.data.summary.MnyHap):'0.00',
          num: res.data.data.length ? res.data.data.length:0,
          alllist: moneyhistory,
          maintype:2
        })
      }
    }
    var res2 = post.getdata(url, datas, datacall);
  },
  //营业记录查询
  yingye: function (mebid, fmebid) {
    var that = this;
    var datas = {};
    var url = "/BO/TR_Detail/Query";
    var where = "AccID = '" + mebid + "' and MebID ='" + fmebid + "'";

    // 获取返利详情
    // console.log(time);
    datas.where = where;
    datas.summary = 1;
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        var moneyhistory = [];
        for (var i = 0; i < res.data.data.length; i++) {
          moneyhistory[i] = res.data.data[i];
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.split(' ')[0];
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.replace("-", '.');
          moneyhistory[i].AccDate = moneyhistory[i].AccDate.replace("-", '.');
        }
        that.setData({
          total: post.toDecimal2(res.data.summary.MnyHap),
          num: res.data.data.length,
          alllist: moneyhistory,
          maintype: 2
        })
      }
    }
    var res2 = post.getdata(url, datas, datacall);
  },
})